package com.cgx.tablet.beeper.utils;




import com.cgx.tablet.beeper.bean.User;
import com.cgx.tablet.beeper.interfaces.UserDataObserver;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户信息相关的类，包含了观察者模式
 * Created by admin on 2016/11/22.
 */
public class UserCache {

    private static List<UserDataObserver> observerList = new ArrayList<>();

    public static User user;

    //注册观察者
    public static void registerUserDataObserver(UserDataObserver observer){
        observerList.add(observer);
    }

    //注销观察，一般在destroy是时候调用
    public static void unRegisterUserDataObserver(UserDataObserver observer){
        observerList.remove(observer);
    }

    //通知每一个观察者，用户信息改变了
    public static void notifyUserDataChanged(){
        for (UserDataObserver observer : observerList){
            observer.onUserDataChanged(user);
        }
    }

}
